//
// Source code recreated from a .class file by IntelliJ IDEA
// (powered by FernFlower decompiler)
//

package com.example.controller;

import com.example.common.Result;
import com.example.entity.Activityapplication;
import com.example.service.ActivityapplicationService;
import com.github.pagehelper.PageInfo;
import jakarta.annotation.Resource;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping({"/activityapplication"})
public class ActivityapplicationController {
    @Resource
    private ActivityapplicationService activityapplicationService;

    public ActivityapplicationController() {
    }

    @GetMapping({"/selectAll"})
    public Result selectAll(Activityapplication activityapplication) {
        List<Activityapplication> list = this.activityapplicationService.selectAll(activityapplication);
        return Result.success(list);
    }

    @GetMapping({"/selectById/{id}"})
    public Result selectById(@PathVariable Integer id, @PathVariable String no) {
        Activityapplication activityapplication = this.activityapplicationService.selectById(id);
        return Result.success(activityapplication);
    }

    @GetMapping({"/selectByOne"})
    public Result selectByOne(@RequestParam Integer id, @RequestParam(required = false) String no) {
        Activityapplication activityapplication = this.activityapplicationService.selectById(id);
        return Result.success(activityapplication);
    }

    @GetMapping({"/selectList"})
    public Result selectList(Activityapplication activityapplication) {
        List<Activityapplication> list = this.activityapplicationService.selectList(activityapplication);
        return Result.success(list);
    }

    /**
     * 活动申请分页查询
     * @param activityapplication
     * @param pageNum
     * @param pageSize
     * @method selectPage
     * @return
     */
    @GetMapping({"/selectPage"})
    public Result selectPage(Activityapplication activityapplication, @RequestParam(defaultValue = "1") Integer pageNum, @RequestParam(defaultValue = "10") Integer pageSize) {
        PageInfo<Activityapplication> pageInfo = this.activityapplicationService.selectPage(activityapplication, pageNum, pageSize);
        return Result.success(pageInfo);
    }

    @PostMapping({"/add"})
    public Result add(@RequestBody Activityapplication activityapplication) {
        this.activityapplicationService.add(activityapplication);
        return Result.success();
    }

    @PutMapping({"/updateById"})
    public Result updateById(@RequestBody Activityapplication activityapplication) {
        this.activityapplicationService.updateById(activityapplication);
        return Result.success();
    }

    @DeleteMapping({"/deleteById/{id}"})
    public Result deleteById(@PathVariable Integer id) {
        this.activityapplicationService.deleteById(id);
        return Result.success();
    }

    @DeleteMapping({"/deleteBatch"})
    public Result deleteBatch(@RequestBody List<Integer> ids) {
        this.activityapplicationService.deleteBatch(ids);
        return Result.success();
    }

    @GetMapping({"/selectByActivityId/{activityId}"})
    public Result selectByActivityId(@PathVariable Integer activityId) {
        List<Activityapplication> list = this.activityapplicationService.selectByActivityId(activityId);
        return Result.success(list);
    }

    @PutMapping({"/updateStatus"})
    public Result updateStatus(@RequestBody Activityapplication activityapplication) {
        this.activityapplicationService.updateStatus(activityapplication);
        return Result.success();
    }

    @GetMapping({"/checkApplicationExistsForActivity"})
    public Result<Activityapplication> checkApplicationExistsForActivity(@RequestParam Integer activityId, @RequestParam Integer studentId) {
        Activityapplication application = this.activityapplicationService.checkApplicationExistsForActivity(activityId, studentId);
        return Result.success(application);
    }
}
